package com.hongdee.market.costtag.controller;

import com.github.pagehelper.PageInfo;
import com.hongdee.base.entity.ResultEntity;
import com.hongdee.common.util.TokenUtil;
import com.hongdee.market.costtag.pojo.CostTagPoJo;
import com.hongdee.market.costtag.service.ICostTagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author zhangkai
 * @desc 一句话描述
 **/
@RestController
@RequestMapping("/mark/predict/costTag")
public class CostTagController {
    @Autowired
    ICostTagService costTagService;

    /**
     * 营销预计-基础配置-消费类别定义-分页查询
     *
     * @param uid
     * @param token
     * @param companyId
     * @param page
     * @param limit
     * @param queryData
     * @return
     * @throws Exception
     */
    @RequestMapping("/page")
    @ResponseBody
    public Map page(@RequestParam(name = "uid", defaultValue = "") String uid,
                    @RequestParam(name = "token", defaultValue = "") String token,
                    @RequestParam(name = "companyId", defaultValue = "") String companyId,
                    @RequestParam(name = "page", defaultValue = "0") int page,
                    @RequestParam(name = "limit", defaultValue = "10") int limit,
                    @RequestBody Map queryData) throws Exception {
        companyId = TokenUtil.getCompanyId(uid);
        PageInfo info = costTagService.page(page, limit, companyId);
        Map map = new HashMap();
        map.put("total", info.getTotal());
        map.put("dataList", info.getList());
        map.put("success", true);
        map.put("msg", "查询成功");
        return map;
    }

    /**
     * 营销预计-基础配置-消费类别定义-保存
     *
     * @param uid
     * @param token
     * @param companyId
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/save")
    @ResponseBody
    public ResultEntity save(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "companyId", defaultValue = "") String companyId,
                             @RequestBody CostTagPoJo data) throws Exception {
        companyId = TokenUtil.getCompanyId(uid);
        data.setCompanyId(companyId);
        costTagService.save(data);
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setMsg("查询成功！");
        resultEntity.setSuccess(true);
        return resultEntity;
    }

    /***
     * 营销预计-基础配置-消费类别定义-修改状态：status 0  停用 1 启用
     * @param uid
     * @param token
     * @param companyId
     * @param id
     * @param status
     * @param data
     * @return
     * @throws Exception
     */
    @RequestMapping("/updateStatus")
    @ResponseBody
    public ResultEntity updateStatus(@RequestParam(name = "uid", defaultValue = "") String uid,
                                     @RequestParam(name = "token", defaultValue = "") String token,
                                     @RequestParam(name = "companyId", defaultValue = "") String companyId,
                                     @RequestParam(name = "id", defaultValue = "") String id,
                                     @RequestParam(name = "status", defaultValue = "") String status,
                                     @RequestBody CostTagPoJo data) throws Exception {
        costTagService.updateStatus(id, status);
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setMsg("更新成功！");
        resultEntity.setSuccess(true);
        return resultEntity;
    }

    /**
     * 营销预计-基础配置-消费类别定义-查询详情
     *
     * @param uid
     * @param token
     * @param companyId
     * @param id
     * @return
     * @throws Exception
     */
    @RequestMapping("/info")
    @ResponseBody
    public ResultEntity info(@RequestParam(name = "uid", defaultValue = "") String uid,
                             @RequestParam(name = "token", defaultValue = "") String token,
                             @RequestParam(name = "companyId", defaultValue = "") String companyId,
                             @RequestParam(name = "id", defaultValue = "") String id) throws Exception {
        CostTagPoJo info = costTagService.info(id);
        ResultEntity resultEntity = new ResultEntity();
        resultEntity.setMsg("查询成功！");
        resultEntity.setData(info);
        resultEntity.setSuccess(true);
        return resultEntity;
    }
}
